package kr.hkit.powerjava.chapter25;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class ParseURLExample {
	public static void main(String[] args) {
		try {
			StringBuilder sb = new StringBuilder();
			URL myURL = new URL("http://www.hkit.kr/SUB/?ctId=49&eduCode=00000027");
			sb.append("protocol = "+myURL.getProtocol()+"\n");
			sb.append("Authorrity ="+myURL.getAuthority()+"\n");
			sb.append("host = "+myURL.getHost()+"\n");
			sb.append("Port = "+myURL.getPort()+"\n");
			sb.append("path = "+myURL.getPath()+"\n");
			sb.append("query = "+myURL.getQuery()+"\n");
			sb.append("filename = "+myURL.getFile()+"\n");
			sb.append("ref = "+myURL.getRef()+"\n");
			System.out.println(sb);
			
			System.out.println("=============================================");
			BufferedReader in = new BufferedReader(new InputStreamReader(myURL.openStream()));
			String line;
			while((line = in.readLine()) != null) {
				System.out.println(line);
			}
			in.close();
		} catch (MalformedURLException e) {
			System.out.println("잘못된 주소 입니다.");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
